<template>
	<view class="container">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-active-color="#facb01" class="swiper">
			<swiper-item><image src="../../static/banner1.png" mode=""></image></swiper-item>
			<swiper-item><image src="../../static/banner2.png" mode=""></image></swiper-item>
		</swiper>
		<view class="navBox">
			<view class="nav active">
				<view class="nav-item" v-for="(item, index) in navlist" :key="index" @click="navToPetFood">
					<image :src="item.imgUrl" mode="widthFix"></image>
					<text>{{ item.text }}</text>
				</view>
			</view>
		</view>

		<view class="discountBox">
			<view class="discountTitle">
				<image src="../../static/th.png" mode="widthFix"></image>
				<text>每日特惠</text>
				<text>距离下一场</text>
				<text>{{ endtime }}</text>
			</view>
			<view class="discount">
				<view class="discount-item" v-for="(item, index) in discountList" :key="index">
					<image :src="item.imgUrl" mode="widthFix"></image>
					<text>{{ item.text }}</text>
					<text>￥{{ item.price }}</text>
				</view>
			</view>
		</view>
		<Recommend></Recommend>
		<Brand></Brand>
	</view>
</template>

<script>
import Recommend from './Recommend.vue';
import Brand from './brand.vue'
export default {
	data() {
		return {
			navlist: [],
			endtime: '20:20:20',
			discountList: [],
			recommendImages: {}
		};
	},
	components: { Recommend,Brand },
	created() {
		// console.log(123);
		this.getnavData();
		this.getdiscount();
	},
	mounted(){
		setInterval(()=>{
			let data=new Date
			this.endtime=(23-data.getHours())+":"+(59-data.getMinutes())+":"+(59-data.getSeconds())
		},1000)
	},
	methods: {
		getnavData() {
			let that = this;
			this.$http({
				url: '/index/navlist',
				success(res) {
					// console.log(res);
					that.navlist = res.data;
				}
			});
		},
		getdiscount() {
			let that = this;
			this.$http({
				url: '/index/discountlist',
				success(res) {
					that.discountList = res.data;
				}
			});
		},
		navToPetFood(){
			console.log(12)
			uni.navigateTo({
				url:"../petfood/petfood",
				fail(err) {
					console.log(err)
				}
			})
		}
	}
};
</script>

<style scoped>
.swiper image {
	width: 100%;
	height: 100%;
}
.navBox {
	position: relative;
	height: 200rpx;
}
.nav {
	width: 100vw;
	height: 200rpx;
	display: flex;
	justify-content: space-around;
	align-items: center;

	position: absolute;
	top: 0;
	left: 0;
}
.active {
	animation: 1.5s navAnimate;
}
.nav-item {
	font-size: 28rpx;
	color: #666;
	margin: 0 20rpx;
}
.nav-item image {
	width: 100%;
}
/* discount */

.discountTitle {
	/* text-indent: 2em; */
	border-top: 6rpx solid #eee;
	padding-top: 8rpx;
	display: flex;
	align-items: center;
}
.discountTitle image{
	width: 40rpx;
	margin-left: 20rpx;
}
.discountTitle text {
	margin: 0 10rpx;
}
.discountTitle text:nth-of-type(1) {
	font-size: 30rpx;
	font-weight: 300;
}
.discountTitle text:nth-of-type(2) {
	font-size: 24rpx;
	font-weight: 400;
	color: #666;
}
.discountTitle text:nth-of-type(3) {
	font-size: 24rpx;
	font-weight: 400;
	color: #666;
}

.discount {
	display: flex;
	justify-content: space-around;
	align-items: center;
	height: 300rpx;
	margin-top: 10rpx;
}
.discount-item {
	height: 100%;
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	align-items: center;
	font-size: 24rpx;
	color: #666;
	margin: 0 20rpx;
}
.discount-item image {
	width: 100%;
	flex: 1;
}

.discount-item :nth-child(3) {
	color: red;
}
@keyframes navAnimate {
	from {
		opacity: 0;
		top: 200rpx;
	}
	to {
		opacity: 1;
		top: 0rpx;
	}
}
</style>
